package com.yinp.proapp.module.customview.simpleness_view.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 * @author yinp.
 * @title
 * @description
 * @date 2019/9/12,16:06.
 */

public class WuJiaoXingView extends View {
    public WuJiaoXingView(Context context) {
        this(context, null);
    }

    public WuJiaoXingView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public WuJiaoXingView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private Paint paint;
    private Paint paint1;

    private void init() {
        paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.YELLOW);

        paint1 = new Paint();
        paint1.setStyle(Paint.Style.STROKE);
        paint1.setColor(Color.RED);
        paint1.setStrokeWidth(8);
    }

    private float centerX;
    private float centerY;
    private int width;
    private int height;
    private static final double ANGLE = 2 * Math.PI / 360 * 108;//108度

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        width = w;
        height = h;
        centerX = w / 2;
        centerY = (float) (centerX * Math.tan(ANGLE / 3));
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        drawXingXing(canvas);
        drawKuang(canvas);
    }

    private void drawXingXing(Canvas canvas) {
        Path path = new Path();
        path.moveTo(centerX, 0);
        float x = (float) (height * Math.tan(ANGLE / 6));
        path.lineTo(centerX - x, height);
        path.lineTo(width, centerY);
        path.lineTo(0, centerY);
        path.lineTo(centerX + x, height);
        path.close();
        canvas.drawPath(path, paint1);
    }

    private void drawKuang(Canvas canvas) {

    }
}
